﻿using System;

namespace FunctionalCLR.Core.Functions.Maths {

    /// <summary>
    /// Return the power of the two operands.
    /// </summary>
    public class PowerNode : OperatorNode {
        public PowerNode()
            : base() {
            Value = "^";
            Precedence = 3;
        }

        public override FuncNode GetReversedFunction(int index) {
            return new LogNode();
        }


        public override object Accept(IVisitor visitor) {
            return visitor.Visit(this);
        }

        public override object Evaluate() {
            double lr = Convert.ToDouble(Left.Evaluate());
            double rr = Convert.ToDouble(Right.Evaluate());

            return Convert.ToDouble(Math.Pow(lr, rr)).ToString();
        }
    }
}
